<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	lang="en">
	
	<h:head>
		<title>Bate Papo</title>
		
		<script type="text/javascript">
			function iniciarChat{
				window.open('sala.jsf','userChatWindow','width=700,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
			}
		</script>

	</h:head>
	
	<h:body>
	<br />
	
	<h:form>
		<h:messages></h:messages>
		<p:panel header="Identificação do usuário" rendered="#{not UsuarioMB.entidadeAutenticado}">
			<br />
			<h:outputLabel for="nome" value="Nome:"></h:outputLabel>
			<br />
			<h:inputText id="nome" required="true" value="#{UsuarioMB.entidade.nome}"/> 
			<br />
			<h:outputLabel for="senha" value="Senha:"/>
			<br />
			<h:inputSecret id="senha" value="#{UsuarioMB.entidade.senha}" required="true"/>
			<br />
			<h:commandButton action="#{UsuarioMB.login}" value="Logar"></h:commandButton>
		</p:panel>
		
		<p:panel header="Home do usuário" rendered="#{UsuarioMB.entidadeAutenticado}">
			<p:poll id="meuPoll" interval="5" update="painelAcoes"></p:poll>
			<h:outputText value="Bem vindo (a),"></h:outputText>
			<strong> <h:outputText value="#{UsuarioMB.entidade.nome}"></h:outputText> </strong>!
			&nbsp;
			<h:commandButton action="#{UsuarioMB.logout}" value="Sair"></h:commandButton>
			<br />
			<br />
			<p:outputPanel id="painelAcoes">
				<p:commandButton value="#{BatePapoMB.quantidadeAtendentes gt 0 ? 'Chat Online' : 'Chat Offline'}"
				action="#{UsuarioMB.iniciarBatePapo}"
				disabled="#{BatePapoMB.quantidadeAtendentes eq 0}"
				oncomplete="iniciarChat();"></p:commandButton>
			</p:outputPanel>
		</p:panel>
	</h:form>
	</h:body>
	
</html>